package com.sy.controller;

import com.sy.dto.JsonResult;
import com.sy.service.UserBlogService;
import com.sy.utils.HttpUtils;
import com.sy.utils.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
public class UserBlogController {
    @Autowired
    private RedisClient redisClient;

    @Autowired
    private UserBlogService userBlogService;

    @Value("${uploadDir}")
    private String uploadDir;

    @Value("${uploadServiceDir}")
    private String uploadServiceDir;

    @Autowired
    private HttpUtils httpUtils;

    @Autowired(required = false)
    private HttpServletResponse res;


    /**根据用户id获取所有博客*/
    @RequestMapping(value = "/userBlogs/{userId}",method = RequestMethod.GET)
    public JsonResult getUserBlogInfo(@PathVariable("userId")Integer userId){
        JsonResult result = userBlogService.getBlogsByUserId(userId);
        res.setStatus(result.getCode());
        return result;
    }


    /**根据博客id删除*/
    @RequestMapping(value ="/userBlogs/{blog}",method = RequestMethod.DELETE)
    public JsonResult removeBlogsByid(@PathVariable("blog")Integer blogId){
        JsonResult result = userBlogService.removeBlogsByid(blogId);
        res.setStatus(result.getCode());
        return result;
    }


}
